package com.five.service.impl;

import com.five.dao.UserMapper;
import com.five.entity.User;
import com.five.service.PasswordHelper;
import com.five.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2018/1/12.
 */

@Service("UserService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper mapper;

    private PasswordHelper passwordHelper = new PasswordHelper();

    @Override
    public void addUser(User user) {
        passwordHelper.encryptPassword(user);
        mapper.insertSelective(user);
    }

    @Override
    public User getUserByIdnumber(String idnumber) {
        return mapper.selectByIdnumber(idnumber);
    }

    @Override
    public void changePassword(User user) {
        passwordHelper.encryptPassword(user);
        System.out.println("userID:"+user.getUserId()+"user password:"+user.getPassword());
        mapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public void changeMoney(User user) {
        mapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public void changePayPassword(User user) {
        mapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public void uploadAvatar(User user) {
        mapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public void updateMyInfo(User user) {
        mapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public User getUserById(int userId) {
        return mapper.selectByPrimaryKey(userId);
    }


}
